package com.syni.mdd.sjb.community.base.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.syni.mdd.sjb.common.component.utils.common.entity.BaseRpVo;
import com.syni.mdd.sjb.common.component.utils.common.utils.ResultMapHelper;
import com.syni.mdd.sjb.community.base.constants.ResultMsg;
import com.syni.mdd.sjb.common.component.mybatis.community.entity.WxCommunityPerson;
import com.syni.mdd.sjb.community.base.entity.vo.rp.communityManagement.ManagementListRpVo;
import com.syni.mdd.sjb.common.component.mybatis.community.mapper.WxCommunityPersonMapper;
import com.syni.mdd.sjb.community.base.service.WxCommunityPersonService;
import org.apache.commons.collections.CollectionUtils;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;
import java.util.Map;

/**
 * <p>
 * 企业微信社群，个人 服务实现类
 * </p>
 *
 * @author lcc
 * @since 2020-11-04
 */
@Service
public class WxCommunityPersonServiceImpl extends ServiceImpl<WxCommunityPersonMapper, WxCommunityPerson> implements WxCommunityPersonService {
    @Autowired
    WxCommunityPersonMapper wxCommunityPersonMapper;
    @Override
    public Map<String, Object> managementList(Integer userId,Integer pageNum,Integer pageSize) {
        ManagementListRpVo managementListRpVo = new ManagementListRpVo();
        Page<WxCommunityPerson> page = new Page(pageNum,pageSize);
        QueryWrapper queryWrapper = new QueryWrapper();
        queryWrapper.eq(WxCommunityPerson.USER_ID,userId);
        queryWrapper.orderByDesc(WxCommunityPerson.ORDER_NUM);
        Page<WxCommunityPerson> wxCommunityPeoplePage = wxCommunityPersonMapper.selectPage(page,queryWrapper);
        List<WxCommunityPerson> wxCommunityPeople = wxCommunityPeoplePage.getRecords();
        if(CollectionUtils.isNotEmpty(wxCommunityPeople)){
            for(WxCommunityPerson wxCommunityPerson : wxCommunityPeople){
                ManagementListRpVo.ManagementElement managementElement = new ManagementListRpVo.ManagementElement();
                BeanUtils.copyProperties(wxCommunityPerson,managementElement);
                managementListRpVo.getManagementLists().add(managementElement);
            }
            BaseRpVo.handlerPage(managementListRpVo,wxCommunityPeoplePage);
        }
        return ResultMapHelper.success(managementListRpVo, ResultMsg.MSG_GET_SUCCESS);
    }
}
